<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>
    <base href="<%=basePath%>" target="_self">
    <title>查询已有用户</title>
    <script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
    <script src="<%=basePath%>component/grid.js"></script>
	<script type="text/javascript" src="<%=basePath%>dwrsystem/interface/userService.js"></script> 
	<script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
	<script type="text/javascript">
	var mygrid;
	var myUnittree;
	var unitId;
	var dhxLayout = createLayoutNormal('1C');

	var dhxGrid = {
		initDataTable : function () {
		    mygrid.setHeader("序号,登录账号,登录姓名,备注");
		    mygrid.setInitWidths("50,150,150,*");
		    mygrid.setColAlign("right,left,left,left");
		    mygrid.setColSorting("int,str,str,str");
		    mygrid.setColTypes("ro,ro,ro,ro");
		    mygrid.attachEvent("onRowDblClicked",this.chooseUser);
		    mygrid.attachEvent("onEnter",this.chooseUser);
		    mygrid.init();
		    setSkin(mygrid);
		    mygrid.loadXML('<%=basePath%>system-user/UserAction!userGrid.action');
		},
		chooseUser : function(rowID,celInd){
			var userName = mygrid.cells(rowID, 2).getValue();
			checkChooseUser(rowID, userName);
		}
	};
	
	function configLayout(){
		var a = dhxLayout.cells('a');
		a.hideHeader();
		a.setText('主页面');
		a.fixSize(true, true);
		mygrid = createGridFromLayoutCell(a);
		createToolbarFromDHXLayoutCell(a,function(toolbar){
		    toolbar.addText("info", 1, "操作:");
		    toolbar.addSeparator("sep1", 2);
		    toolbar.addButton("cancel", 3, "取消", "undo.gif", "undo_dis.gif");
		    toolbar.attachEvent("onClick", function(id) {
		    	if(id == 'cancel'){
		    		parent.closeUsers();
		    	}
		    });
		});
	}

	$(function (){
		configLayout()
		dhxGrid.initDataTable();
	 	myUnittree = parent.window.MyTree;
	 	unitId = '${param.unitId}';
	});
	</script>
</head>
  
<body>
</body>

<script type="text/javascript">
function checkChooseUser(userId, userName){
	waitingWindow();
	userService.selectExistTUserFromUnit(userId, unitId, function(data){
		if(data == true){
			parent.myAlert('本单位下已经存在此用户');
			return;
		}else{
			userService.insertTUserUnit({userMainId:userId, unitId:unitId});
			myUnittree.addNode(unitId, userId + '|' + unitId, userName, 0, "man.gif", 0, 0, "");
			myUnittree.setUserDataAttr(userId, "type", "user");
			//parent.window.location.href = '<%=basePath%>page/system/user/user_list.jsp?unitId='+ unitId;
			parent.window.dhxLayout.cells('b').attachURL('<%=basePath%>page/system/user/user_list.jsp?unitId='+ unitId);
			parent.closeUsers();
		}
	});
}
</script>

</html>
